package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.CategoryAddReq;
import com.yimils.core.goods.dto.CategoryUpdateReq;
import com.yimils.core.goods.serivce.CategoryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class CategoryController {
    @Resource(name = "categoryService")
    CategoryService categoryService;

    /**
     * showdoc
     *
     * @return {"code":0,"msg":"操作成功"}
     * @catalog 品牌管理/品牌管理
     * @title 添加品牌
     * @description 添加品牌
     * @json_param {"brandName":"特步","supplierId":"32"}
     * @method post
     * @url /brand/save
     * @return_param code   Integer     状态码
     * @return_param msg   String    消息
     * @number 3
     */
    @PostMapping("/category/save")
    public RspBase saveCategory(@RequestBody CategoryAddReq categoryAddReq) {
        if (categoryService.saveCategory(categoryAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @PutMapping("/category/update")
    public RspBase updateCategory(@RequestBody CategoryUpdateReq categoryUpdateReq) {
        if (categoryService.updateCategory(categoryUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @DeleteMapping("/category/delete")
    public RspBase deleteCategory(@RequestBody List<Long> categoryIds) {
        if (categoryService.deleteCategory(categoryIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @GetMapping("/category/list")
    public RspBase listCategory() {
        RspBase rsp = RspBase.OK();
        rsp.put("data", categoryService.listCategory());
        return rsp;
    }
}
